package com.jxwifi.cloud.quickclean.order;

import android.content.Context;
import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.TextView;

import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.adapter.TabPageAdapter;
import com.jxwifi.cloud.quickclean.fragment.CleaningOrderFragment;
import com.jxwifi.cloud.quickclean.fragment.KTOrderFragment;
import com.jxwifi.cloud.quickclean.model.AuzImpl;

import java.util.ArrayList;
import java.util.List;

public class OrderPresenter {

    private Context mContext;
    private OrderView mView;
    private AuzImpl mAuz;
    private String[] mTabNames = {"保洁订单", "工具包订单"};


    public OrderPresenter(Context context, OrderView view) {
        this.mContext = context;
        this.mView = view;
        this.mAuz = new AuzImpl();
    }

    public void fgView() {
        List<Fragment> fragment = new ArrayList<Fragment>();
        CleaningOrderFragment mcleaningOrderFragment = new CleaningOrderFragment();
        KTOrderFragment mKTOrderFragment = new KTOrderFragment();
        fragment.add(mcleaningOrderFragment);
        fragment.add(mKTOrderFragment);
        TabPageAdapter pageAdapter = new TabPageAdapter(mView.getFrgaments(), fragment, mTabNames);
        pageAdapter.notifyDataSetChanged();
        mView.getPage().setAdapter(pageAdapter);
        mView.getTabLayouts().setupWithViewPager(mView.getPage());
        mView.getTabLayouts().setSelectedTabIndicatorHeight(0);

        //字体颜色的设置第一种写法无效，需要用第二种才能生效
        //mView.getTabLayouts().setTabTextColors(R.color.color_white,R.color.color_text5);
        mView.getTabLayouts().setTabTextColors(Color.parseColor("#A7A7A7"), Color.parseColor("#3DB64D"));
        //设置监听
        mView.getTabLayouts().addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                //tab项选中状态时执行

                mView.getPage().setCurrentItem(tab.getPosition());
                View view = tab.getCustomView();
                if (null != view && view instanceof TextView) {
                    ((TextView) view).setTextColor(ContextCompat.getColor(mContext, R.color.color_text5));
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                //tab项取消选中状态时执行
                // Toast.makeText(mContext, "第"+tab.getPosition()+"tab选项的onTabUnselected", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                //tab项选中状态再次点击时执行
                //Toast.makeText(mContext, "第"+tab.getPosition()+"tab选项的onTabReselected", Toast.LENGTH_SHORT).show();
            }
        });
    }

}
